<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="CSI.Directory.Core.Model"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
 <title>Manage Directory</title>
    <link href="../../Assets/CSS/mstyle.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript">
   
    
    </script>
</head>
<body  style="background-color:#000">
    
    <div id="nav">
    <h2>Manage Directory</h2><br />
    <ul>
        <li>Listings</li>
        <li class="inactive"><a href="/Directory/Manage/Categories">Categories</a></li>
        <li class="inactive"><a href="/Directory/Manage/Features">Features</a></li>
    </ul>
    <div id="subNav">
        Listings
        <div id="main">
            
           <table>
           <tr>
                    <td align="left" width="" colspan="2">
                    
                    <%if(((IList<Listing>)ViewData["Listings"]).Count > 0){%>
                        <table cellpadding="5" cellspacing="5" border="0" style="width:900">
                            <tr>
                                <td align="center"><div style="width:75px"><b>Approve</b><br /><a href="" onclick="ApproveAll();return false;">select all</a></div>
                                </td>
                                <td align="center"><div style="width:75px"><b>Deny</b><br /><a href="" onclick="DenyAll();return false;">select all</a></div>
                                </td>
                                <td><b>Listings</b><div style="height:12px"></div>
                                </td>
                            </tr>
                            <%
                            foreach (var listing in (IList<Listing>)ViewData["Listings"])
                            { %>
                                <tr>
                                     <td ><input type="radio" id="<%=listing.Id %>" value="approved" name="<%=listing.Id %>" />
                                    </td>
                                    <td ><input type="radio" id="<%=listing.Id %>" value="denied" name="<%=listing.Id %>" />
                                    </td>
                                    <td>
                                    <div style="width:500px">
                                     <%if (!string.IsNullOrEmpty(listing.Image))
                                       { %>
                                        <img src="/Assets/Images/<%=listing.Image %>" style="float:left" />
                                     <%} %>
                                     Title: <%=listing.Name %><br />
                                     Url: <%=listing.Url %><br />
                                     Phone: <%=listing.Phone %>   Email: <%=listing.Email %><br />
                                     Address: <%=listing.AddressLine1 %><br />
                                     <%if (!string.IsNullOrEmpty(listing.AddressLine2))
                                       { %>
                                        <%=listing.AddressLine2 %><br />
                                     <%} %>
                                     
                                     City: <%=listing.City %> State: <%=listing.State %><br />
                                     
                                     Description: <p style="width:300px;white-space: normal;word-wrap:break-word;"><%=listing.Description %></p><br />
                                     Keywords: <%=listing.Keywords %><br />
                                     
                                     Categories <br />
                                     <ul style="display:block">
                                     <%
                                    foreach (var c in listing.Categories)
                                    {%>
                                       <li><%=c.Name %></li>
                                    <%} %> 
                                     </ul>
                                     
                                    </div> 
                                    </td>
                                
                                </tr>
                                
                           <% } %>                            
                           </tr>
                        </table>
                        <a href="" onclick="ManageListings(); return false;">Save</a>
                        
                     <% } else{%>
                        
                            No new listings.
                        
                      <% } %>      
                    
                    </td>
                   
               </tr>
           </table>
           <br />
            
            <div id="error"></div>
    

        </div>
    </div>
    </div>
</body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="../../Assets/Scripts/jquery.toJson.js" type="text/javascript"></script>
<script type="text/javascript">
var data = new Array();
function ManageListings()
{
     selections =  $("input[type='radio']:checked");
     
      $.each(selections, function(i,item)
         {

            data[i] = { 
                        ID: item.id,
                        Approved: (item.value == ("approved") ? 1 : 0),
                        Denied:  (item.value == ("denied") ? 1 : 0)
                      }; 
                    
         });
//          var u = "/Signature/AddActivations/?profile=" + profile;
//         if(profile == "coa")
//            u = "/Signature/AddCourseActivations/?profile=" + profile;
//         
//         
         var encoded = $.toJSON(data);
         $.ajax({
                    url:"/Directory/Manage/ManageListings", 
                    type: "POST",
                    dataType: 'json',
                    data: encoded,
                    contentType: "application/json; charset=utf-8",
                    success: function(data) {
                        if(data.Successful)
                            window.location.reload();
                        else
                            $("#error").html(data.Exception); 
                    }
                });

}

function ApproveAll()
{
    selections =  $("input[type='radio']");
     
      $.each(selections, function(i,item)
         {

           if(item.value == "approved")
           item.checked = true;
                    
         });
}
function DenyAll()
{
    selections =  $("input[type='radio']");
     
      $.each(selections, function(i,item)
         {

           if(item.value == "denied")
           item.checked = true;
                    
         });
}
</script>
</html>

